/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import dao.AddressDao;
import dao.MemberDao;
import entity.Member;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author zhang
 */
@WebServlet("/aas")
public class AddAddressServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name=(String)req.getSession().getAttribute("username");
        Member member=new MemberDao().getMemberByName(name);
        int memberId=member.getId();
        String address=req.getParameter("address");
        String addressee=req.getParameter("addressee");
        String phone=req.getParameter("phone");
        int zipcode=Integer.parseInt(req.getParameter("zipcode"));
        Boolean bool=new AddressDao().addAddress(memberId,address,addressee,phone,zipcode);
        
        resp.setContentType("text/html;charset=utf-8");
        if(bool==false){
            resp.getWriter().println("<h1>添加收货地址失败！</h1>");
        }
        else{            
            resp.getWriter().println("<h1>添加收货地址成功！</h1>");
        }
        resp.getWriter().println("<a href='Member.jsp?name="+name+"'>返回个人主页</a>");
    }
    
}
